/**
 * @file mainTask.c
 * @author  xiaowine (xiaowine@sina.cn)
 * @brief
 * @version 01.00
 * @date    2025-08-31
 *
 * @copyright Copyright (c) {2020}  xiaowine
 *
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version <th>Author  <th>Description
 * <tr><td>2025-08-31 <td>1.0     <td>wangh     <td>内容
 * </table>
 * ******************************************************************
 * *                   .::::
 * *                 .::::::::
 * *                ::::::::::
 * *             ..:::::::::::
 * *          '::::::::::::
 * *            .:::::::::
 * *       '::::::::::::::..        女神助攻,流量冲天
 * *            ..::::::::::::.     永不宕机,代码无bug
 * *          ``:::::::::::::::
 * *           ::::``:::::::::'        .:::
 * *          ::::'   ':::::'       .::::::::
 * *        .::::'      ::::     .:::::::'::::
 * *       .:::'       :::::  .:::::::::' ':::::
 * *      .::'        :::::.:::::::::'      ':::::
 * *     .::'         ::::::::::::::'         ``::::
 * * ...:::           ::::::::::::'              ``::
 * *```` ':.          ':::::::::'                  ::::.
 * *                   '.:::::'                    ':'````.
 * ******************************************************************
 */

/* Private includes ----------------------------------------------------------*/
#include <string.h>
#include "main.h"
#include "timBsp.h"
#include "userUsart.h"

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/

/* Private variables ---------------------------------------------------------*/

#include "userUsart.h"

void mainInit(void)
{
    HAL_UARTEx_ReceiveToIdle_DMA(&huart1, rx1DMAbuffer, USART_REC_LEN);
    printf("\r\nHAL_UARTEx_ReceiveToIdle_DMA:\r\n");
}

void mainTask(void)
{
    if(_TKS_FLAGA_1ms)
    {
        _TKS_FLAGA_1ms = 0;
        // 1ms定时任务
    }
    if(_TKS_FLAGA_2ms)
    {
        _TKS_FLAGA_2ms = 0;
        // 2ms定时任务
    }
    if(_TKS_FLAGA_5ms)
    {
        _TKS_FLAGA_5ms = 0;
        // 5ms定时任务
    }
    if(_TKS_FLAGA_10ms)
    {
        _TKS_FLAGA_10ms = 0;
        // 10ms定时任务
    }
    if(_TKS_FLAGA_20ms)
    {
        _TKS_FLAGA_20ms = 0;
        // 20ms定时任务
    }
    if(_TKS_FLAGA_50ms)
    {
        _TKS_FLAGA_50ms = 0;
        // 50ms定时任务
    }
    if(_TKS_FLAGA_100ms)
    {
        _TKS_FLAGA_100ms = 0;
        // 100ms定时任务
    }
    if(_TKS_FLAGA_500ms)
    {
        _TKS_FLAGA_500ms = 0;
        // 500ms定时任务
        HAL_GPIO_TogglePin(LED3_GPIO_Port, LED3_Pin);  // 翘板灯
    }

    if(USART_RX_STA & 0x8000)
    {
        printf("\r\n您发送的消息为:\r\n");
        memcpy(tx1DMAbuffer, rx1Buffer, rx1Count);
        HAL_UART_Transmit_DMA(&huart1, tx1DMAbuffer, rx1Count);
        rx1Count     = 0;
        USART_RX_STA = 0;
    }
}
